/*
    XTU OJ: 1048
    by: fifth_light
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define SCALE_SIZE 128

int total_size = SCALE_SIZE;
int size = 0;
int* box;

void init_box() {
    box = (int*) malloc(sizeof(int) * total_size);
}

void put_box(int number) {
    if (total_size == size) {
        int new_size = total_size + SCALE_SIZE;
        box = (int*) realloc(box, sizeof(int) * new_size);
        total_size = new_size;
    }
    int pos = 0;
    for (int i = 0; i < size; i++) {
        if (box[i] > number) {
            pos = i;
            break;
        }
        if (i == size - 1) {
            pos = size;        
        }
    }
    
    if (pos != size) {
        memmove(&box[pos + 1], &box[pos], sizeof(int) * (size - pos));
        box[pos] = number;
    } else {
        box[size] = number;
    }
    size++;
}

int main(void) {
    init_box();
    char command[16];
    int number;
    int get_count = 0;
    while (scanf("%s", command) > 0) {
        if (strcmp(command, "ADD") == 0) {
            scanf("%d", &number);
            put_box(number);
        } else if (strcmp(command, "GET") == 0) {
            printf("%d\n", box[get_count++]);
        }
    }
    return 0;
}
